﻿<%@ Page Title="自定义内容管理" Language="C#" MasterPageFile="Function.Master" AutoEventWireup="true" CodeBehind="CustomSectionList.aspx.cs" Inherits="LEARNREN.COM.WebSite.Admin.CustomSectionList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../umeditor1_2_2-utf8-net/themes/default/css/umeditor.min.css" rel="stylesheet" type="text/css" />
    <script src="../umeditor1_2_2-utf8-net/umeditor.config.js" type="text/javascript"></script>
    <script src="../umeditor1_2_2-utf8-net/umeditor.min.js" type="text/javascript"></script>
    <script src="../umeditor1_2_2-utf8-net/lang/zh-cn/zh-cn.js" type="text/javascript"></script>
    <script type="text/javascript">
        var edit_pannel;
        var dataTableInPage;
        var um;

        $(document).ready(function () {
            dataTableInPage = showDataTable();
            init_edit_pannel();
            initButton();
        });
        function showDataTable() {
            var dt = dataTableExt("CustomSectionList.ashx", "dataTable",
                        [{ "sClass": "center", "mDataProp": "Id", "width": 60 },
                        { "sClass": "center", "mDataProp": "Title" },
                        { "sClass": "center", "mDataProp": "CreatedTime", "width": 130 },
                        {
                            //自定义列
                            "mDataProp": "Id",
                            "width": 120,
                            "sClass": "center",
                            "bSearchable": false,
                            "bStorable": false,
                            "bStateSave": true,
                            "mRender": function (obj, display, fullData) {
                                return '<a href=\"#\" class="inlineButton" onclick=\"showEditpannel(1,' + obj + ');return false;\">编辑</a>&nbsp;&nbsp;<a href=\"#\" class="inlineButton" onclick=\"deleteCS(' + obj + ');return false;\">删除</a>';
                            }
                        }]);
            return dt;
        }

        /*o:当前的操作编码0：添加，1：修改，2：删除*/
        function showEditpannel(o, id) {
            $("#hid_operation").val(o.toString());
            if (o == 0) {
                edit_pannel.title = "添加自定义内容片断";
                $("#hid_id").val("");
                $("#txt_title").val("");
                $("#txt_content").val("");
            }
            else if (o == 1) {
                edit_pannel.title = "修改自定义内容片断";
                $.post("CustomSectionHandler.ashx",
                   { o: 3, id: id },
                    function (data) {
                        if (!data) {
                            showDialog("应用程序内部错误", "提示");
                            return false;
                        }

                        if (data.State) {
                            $("#hid_id").val(id);
                            $("#txt_title").val(data.Data.Title);
                            //$("#txt_content").val(data.Data.Content);
                            um.setContent(data.Data.Content);
                        } else {
                            showDialog(data.Message, "提示");
                        }
                    },
                     "json");

            }
            edit_pannel.dialog("open");
            return false;
        }

        function saveSection() {
            var o = $("#hid_operation").val();
            var id = $("#hid_id").val();
            var title = $("#txt_title").val();
            var content = $("#txt_content").val();
            $.post("CustomSectionHandler.ashx",
            { o: o, id: id, title: title, content: content },
            function (data) {
                if (!data) {
                    showDialog("保存失败！", "提示");
                }
                else if (data.result) {
                    edit_pannel.dialog("close");
                    dataTableInPage.fnStandingRedraw();
                }
                else {
                    showDialog(data.msg, "提示");
                }
            },
            "json");
        }

        function deleteCS(id) {
            if (confirm("确定要删除此内容吗？")) {
                $.post("CustomSectionHandler.ashx",
                { o: 2, id: id },
                function (data) {
                    if (!data) {
                        showDialog("删除失败！", "提示");
                    }
                    else {
                        if (data.result) {
                            showDialog("删除成功！", "提示");
                            if (dataTableInPage) {
                                dataTableInPage.fnStandingRedraw();
                            }
                        }
                        else {
                            showDialog(data.msg, "提示");
                        }
                    }
                },
                "json");
            }
            return false;
        }

        function init_edit_pannel() {
            um = UM.getEditor("txt_content", { toolbar: [
            'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
            'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize',
            '| justifyleft justifycenter justifyright justifyjustify |',
            'link unlink | emotion image video  | map',
            '| horizontal print preview', 'drafts', 'formula']
            });
            um.setWidth("100%");
            um.setHeight("250");
            $(".edui-body-container").css("width", "");


            edit_pannel = $("#edit_pannel").dialog({
                autoOpen: false,
                title: "编辑自定义内容片断",
                modal: true,
                buttons: {
                    "确定": function () { saveSection(); },
                    "取消": function () { $(this).dialog("close"); }
                },
                width: 600
            });

            edit_pannel.find("form").submit(function (event) {
                event.preventDefault();
                saveSection();
            });
        }

        function initButton() {
            $("#addbtn").click(function () {
                showEditpannel(0);
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div style="margin-bottom:5px;">
        <button id="addbtn" value="添加自定义区块">添加自定义区块</button>
    </div>
    <table id="dataTable" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>序号</th>
                <th>标题</th>
                <th>发布时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
    <div id="edit_pannel" title="修改自定义内容片断">
        <form action="Logout.aspx" method="post">
        <p>
            <label for="txt_title" style="display: block;">标题</label>
            <input id="txt_title" name="txt_title" type="text" /></p>
        <p>
            <label for="txt_content" style="display: block;">内容</label>
            <textarea rows="5" id="txt_content" name="txt_content"></textarea></p>
        <input type="hidden" id="hid_id" name="hid_id" />
        <input type="hidden" id="hid_operation" name="hid_operation" />
        <input type="submit" tabindex="-1" style="position: absolute; top: -1000px" />
        </form>
    </div>
</asp:Content>
